﻿Public Class DataSetUtils

#Region "DataTable methods"

    Public Shared Function GetDataRowDate(ByVal dr As DataRow, ByVal columnName As String) As DateTime
        If IsDBNull(dr(columnName)) Then
            Return DateTime.MinValue
        Else
            Return Convert.ToDateTime(dr(columnName))
        End If
    End Function

    Public Shared Function GetDataRowGuid(ByVal dr As DataRow, ByVal columnName As String) As Guid
        If IsDBNull(dr(columnName)) Then
            Return GUID.Empty
        Else
            Return dr(columnName)
        End If
    End Function

    Public Shared Function GetDataRowString(ByVal dr As DataRow, ByVal columnName As String) As String
        If IsDBNull(dr(columnName)) Then
            Return ""
        Else
            Return dr(columnName)
        End If
    End Function

    Public Shared Function GetDataRowBoolean(ByVal dr As DataRow, ByVal columnName As String) As Boolean
        If IsDBNull(dr(columnName)) Then
            Return False
        Else
            Return CType(dr(columnName), Boolean)
        End If
    End Function


    Public Shared Function GetDataRowInt(ByVal dr As DataRow, ByVal columnName As String) As Integer
        If IsDBNull(dr(columnName)) Then
            Return 0
        Else
            Return Integer.Parse(dr(columnName))
        End If
    End Function

    Public Shared Function GetDataRowDouble(ByVal dr As DataRow, ByVal columnName As String) As Double
        If IsDBNull(dr(columnName)) Then
            Return 0
        Else
            Return Double.Parse(dr(columnName))
        End If
    End Function

    Public Shared Function GetDataRowObject(ByVal dr As DataRow, ByVal columnName As String) As Object
        If IsDBNull(dr(columnName)) Then
            Return Nothing
        Else
            Return dr(columnName)
        End If
    End Function


#End Region

End Class
